<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  var ws = new WebSocket('ws://localhost:3000/test');
  console.log(ws)

// 打开WebSocket连接后立刻发送一条消息:
    // ws.onopen(function () {
    //     console.log(`[CLIENT] open()`);
    //     ws.send('Hello!');
    // });
    ws.onopen = function (e) {
        console.log(console.log(e));
        ws.send('Hello!');
    }

    // 响应收到的消息:
    ws.onmessage =function (message) {
        // document.write(JSON.stringify(message))
        // console.log(`[CLIENT] Received: ${message}`);
        console.log(message)
    }
</script>
</html>